package hxy.dragon.spring.webflux.router;

import hxy.dragon.spring.webflux.handler.HelloWorldHandlerFunction;
import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

/**
 * @author eric
 * @program spring-webflux
 * @description  相当于 RequestMapping
 * @date 2020/3/21
 */
@Component
public class HelloWorldRouter {
    @Bean
    public RouterFunction<ServerResponse> routerHelloWorld(HelloWorldHandlerFunction helloWorldHandlerFunction){
        return RouterFunctions.route((RequestPredicates.GET("hello-flux")).and(RequestPredicates.accept(MediaType.APPLICATION_JSON)),helloWorldHandlerFunction::handle);
    }
}
